<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'user') {
    header("Location: ../login.php");
    exit();
}

require '../config.php';

$post_id = $_GET['id'];
$user_id = $_SESSION['user_id'];

// 删除帖子
$stmt = $conn->prepare("DELETE FROM posts WHERE id = ? AND user_id = ?");
$stmt->bind_param("ii", $post_id, $user_id);

if ($stmt->execute()) {
    header("Location: index.php");
    exit();
} else {
    echo "<p class='error'>删除帖子失败，请重试</p>";
}

$stmt->close();
$conn->close();
?>